package cn.kgc.crowdfundingadminspringboot3.controller;

import cn.kgc.crowdfundingadminspringboot3.common.ResultEntity;
import cn.kgc.crowdfundingadminspringboot3.pojo.Auth;
import cn.kgc.crowdfundingadminspringboot3.service.AuthService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/auth")
public class AuthController {

    @Resource
    AuthService authService;

    @RequestMapping("/get/all/auth")
    @ResponseBody
    public ResultEntity<List<Auth>> getAllAuth(){
        List<Auth> authList = authService.getAllAuth();
        return ResultEntity.successWithoutData(authList);
    }
    @ResponseBody
    @RequestMapping("/get/assigned/auth/id/list")
    public ResultEntity<List<Integer>> getAssignedAuthIdList(@RequestParam("roleId") Integer roleId) {

        List<Integer> authIdList = authService.getAssignedAuthIdList(roleId);

        return ResultEntity.successWithoutData(authIdList);
    }

    @ResponseBody
    @RequestMapping("/do/assign")
    public ResultEntity<String> doRoleAssignAuth(
            @RequestBody Map<String, List<Integer>> assignDataMap) {

        authService.updateRelationShipBetweenRoleAndAuth(assignDataMap);

        return ResultEntity.successWithoutData();
    }
}
